<?php
/**
 * Created by PhpStorm.
 * User: cc
 * Date: 2024/5/24
 * Time: 15:50
 */

namespace app\astrologer\controller\v7;

use app\astrologer\controller\AstrAuth;
use app\common\cachemodel\ZlcrAstr;

class User extends AstrAuth
{
    protected $defaultChat = "Hi，很高兴为你服务！\r\n你可以和我聊聊你的疑惑，或者直接向我咨询。";//todo 默认对话内容

    /**
     * 获取默认对话
     * @return \think\response\Json
     */
    public function defaultChat()
    {
        $extend = $this->astrInfo['extend'];
        return show(config('code.success'), 'success', $extend['default_chat'] ?? $this->defaultChat);
    }

    /**
     * 设置默认对话
     * @return \think\response\Json
     */
    public function setDefaultChat()
    {
        $type = input('type/d', 1);//1=>更新对话信息  2=>恢复默认对话信息
        $content = input('content/s', '');
        $extend = $this->astrInfo['extend'];
        if ($type === 1)
        {
            if (!$content)
            {
                return show(config('code.error'), '请输入内容');
            }
            $extend['default_chat'] = $content;
        } else
        {
            $extend['default_chat'] = $this->defaultChat;//默认对话内容
        }
        $data['extend'] = json_encode($extend, JSON_UNESCAPED_UNICODE);
        (new ZlcrAstr())->UpdateData($this->astrInfo['id'], ['id' => $this->astrInfo['id']], $data);
        return show(config('code.success'), 'success');
    }

    /**
     * 获取资质证书列表
     * @return \think\response\Json
     */
    public function certificateList()
    {
        $extend = $this->astrInfo['extend'];
        $res = [];
        if (isset($extend['certificate']))
        {
            foreach ($extend['certificate'] as $item)
            {
                $res[] = [
                    'title' => $item['name'],
                    'img' => $item['pic']
                ];
            }
        }
        return show(config('code.success'), 'success', $res);
    }
}
